package com.onedec.materials.service.serviceimp;

import com.onedec.materials.entity.OnedecMaterial;
import com.onedec.materials.mapper.OnedecMaterialMapper;
import com.onedec.materials.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class MaterialServiceImp implements MaterialService {
    @Autowired
    private OnedecMaterialMapper materialMapper;
    /**
     * 添加材料
     * @param onedecMaterial
     * @return
     */
    @Override
    public int insetMaterial(OnedecMaterial onedecMaterial) {
        int insert = materialMapper.insert(onedecMaterial);
        return insert;
    }

    /**
     * 修改材料信息
     * @param onedecMaterial
     * @return
     */
    @Override
    public int updateMaterial(OnedecMaterial onedecMaterial) {
        int i = materialMapper.updateByPrimaryKeySelective(onedecMaterial);
        return i;
    }

    /**
     * 查询所有材料
     * @return
     */
    @Override
    public List<OnedecMaterial> selectAllMaterial() {
        List<OnedecMaterial> list = materialMapper.selectByExample(null);
        return list;
    }

    /**
     * 根据id查找
     * @param materialId
     * @return
     */
    @Override
    public OnedecMaterial selectId(int materialId) {
        OnedecMaterial material = materialMapper.selectByPrimaryKey(materialId);
        return  material;
    }

    /**
     * 根据id删除
     * @param materialId
     * @return
     */
    @Override
    public int deleteMaterial(int materialId) {
        int i = materialMapper.deleteByPrimaryKey(materialId);
        return i;
    }

    /**
     * 根据名称以及型号查找
     * @param map
     * @return
     */
    @Override
    public List<OnedecMaterial> selectNameandModl(Map<String, Object> map) {
        List<OnedecMaterial> list = materialMapper.selectNameandModel(map);
        return list;
    }

    @Override
    public List<Map<String, Object>> selectInTable(Map<String, Object> map) {
        List<Map<String, Object>> maps;
        maps = materialMapper.selectInTable(map);
        return maps;
    }

    @Override
    public List<Map<String, Object>> selectmAndp() {
        List<Map<String, Object>> maps = materialMapper.selectmAndp();
        return maps;
    }

    @Override
    public List<Map<String, Object>> findBymAndp(int materialId) {
        List<Map<String, Object>> list = materialMapper.findBymAndp(materialId);
        return list;
    }

}
